package com.polaris.live.popup

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.adapter.GameDetailTypeAdapter
import com.polaris.live.databinding.PopupGameDetailBinding
import com.polaris.live.resp.bean.GameDetailTypeBean
import com.polaris.live.translation.R.string

/**
 * GameDetailPopup
 *
 * @author Created by 半仙 on 2024/3/18/018 20:03
 */
class GameDetailPopup(
    context: Context,
    private val mSelectPosition: (type: Int?) -> Unit,
) : BottomPopupView(context) {
    override fun getImplLayoutId() = R.layout.popup_game_detail

    private lateinit var mBinding: PopupGameDetailBinding

    private val mAdapter by lazy { GameDetailTypeAdapter() }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupGameDetailBinding.bind(popupImplView)
        mBinding.gameDetailRecycler.apply {
            adapter = mAdapter
            layoutManager = LinearLayoutManager(context)
        }

        mAdapter.setList(mTypeList)

        mAdapter.setOnItemClickListener { _, _, position ->
            when (position) {
                0 -> {
                    mSelectPosition.invoke(null)
                }

                mTypeList.size - 1 -> {}
                else -> {
                    mSelectPosition.invoke(mAdapter.getItem(position).type)
                }
            }
            dismiss()
        }
    }

    companion object {
        val mTypeList = listOf(
            GameDetailTypeBean(StringUtils.getString(string.all), null),
            GameDetailTypeBean(StringUtils.getString(string.casual_games), 0),
            GameDetailTypeBean(StringUtils.getString(string.platform_reward), 3),
//            GameDetailTypeBean(StringUtils.getString(string.task), 1),
            GameDetailTypeBean(StringUtils.getString(string.exchange), 2),
            GameDetailTypeBean(StringUtils.getString(string.recharge), 4),
            GameDetailTypeBean(StringUtils.getString(string.dress_up), 5),
            GameDetailTypeBean(StringUtils.getString(string.room_string), 6),
            GameDetailTypeBean(StringUtils.getString(string.cancel), null)
        )
    }

}